package com.zjl.controller;

import com.zjl.service.WalletService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Author EternalPain
 * @Date 2023/1/31 18:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/wallet")
public class WalletController {

    @Resource
    public WalletService walletService;

    /**
     * 用户消费100元
     */
    @GetMapping("/consumeMoney")
    public String consumeMoney() {
        if (walletService.consumeMoney(1, BigDecimal.valueOf(100))) {
            return "用户消费100元成功！";
        } else {
            return "用户消费100元失败，余额不足！";
        }
    }

    /**
     * 用户退款20元
     */
    @GetMapping("/refund")
    public String refund() {
        if (walletService.refund(1, BigDecimal.valueOf(20))) {
            return "用户退款20元成功！";
        } else {
            return "用户退款20元失败！";
        }
    }

}
